package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.geom.*;
	
	public class AlgrPixelbasedAction extends AbstractAction
	{
		private var operator:String;
		private var other:BitmapData;
		
		public function setValue(s:String, o:BitmapData):void
		{
			this.operator = s;
			this.other = o;	
		}
		
		public override function getDescription():String
		{
			var desc:String = this.operator.toLocaleUpperCase();
			return "Algebraic (" + desc + ")";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var w:int = Math.min(old.width, this.other.width);
			var h:int = Math.min(old.height, this.other.height);
			var ret:BitmapData = new BitmapData(w, h);
			
			for(var i:int = 0; i < w; i++)
			{
				for(var j:int = 0; j < h; j++)
				{
					var c:uint;
					var o1:uint = old.getPixel(i, j);
					var o2:uint = this.other.getPixel(i, j);
					switch(this.operator)
					{
						case 'minus':
							c = o1 - o2;
							break;	
						case 'divide':
							c = (o1 / o2) * 0xffffff;
							break;
					}
					ret.setPixel(i, j, c); 
				}
			}
			
			return ret;
			return ret;
		}	
	}
}